/*
	Copyright (C) 2008 Demiurg-HG

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#pragma once	

#include "..\library\library.h"


const uint NN_MAX_LAYERS	=	16;

class EPerceptron {
	friend class ENeuralNetwork;
	public:
						EPerceptron		( uint num_inputs );
						~EPerceptron	( void );
		float			Evaluate		( const vector<float> &input ) const;
	protected:
		vector<float>	weights;	  // last element is used for offset (or shift?)
	};

class ENetworkLayer {
	friend class ENeuralNetwork;
	public:
						ENetworkLayer	( uint num_slps, uint num_inputs );
						~ENetworkLayer	( void );
		void			Evaluate		( const vector<float> &input, vector<float> &output ) const;
						
	protected:
		uint	input_number;
		vector<EPerceptron*> slps;
	};


class ENeuralNetwork {
	public:
					ENeuralNetwork		( uint num_inputs, uint num_layers, const uint *num_perceptron);
					~ENeuralNetwork		( void );
		
		void		EvaluateNetwork		( const vector<float> &input, vector<float> &output ) const;
		float		TrainNetwork		( const vector<float> &input, const vector<float> &target_output, float train_norm );
		
	protected:
		vector<ENetworkLayer*>	layers;
	};